﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Collections;

namespace GDIPlusDemo
{
    public partial class weatherDataAny : Form
    {
        public weatherDataAny()
        {
            InitializeComponent();
        }

        private void butGetWea_Click(object sender, EventArgs e)
        {
            try
            {
                tt.WeatherWebService w = new tt.WeatherWebService();
                // Weather.
                //把webservice当做一个类来操作
                string[] s = new string[23];//声明一个string数组存放其返回的结果
                //string c = this.textBox2.Text.Trim();//获得文本框2的内容
                s = w.getWeatherbyCityName(textBoxCity.Text.Trim());
                // s = w.getSupportProvince();
                //以文本框内容为变量实现方法getWeatherbyCityName
                if (s[8] == "")
                {
                    MessageBox.Show("暂时不支持您查询的城市");
                }
                else
                {
                    textBoxCity.Text = s[0].Trim() + s[1].Trim();
                    labelCondition.Text = s[10].Split(":".ToCharArray())[0];
                    labelDay1.Text = s[6].Trim();
                    labelTemp1.Text = s[5].Trim();
                    picDay11.Image = Image.FromFile(@"e:\weatherPic\" + s[8] + "");
                    picDay12.Image = Image.FromFile(@"e:\weatherPic\" + s[9] + "");
                    labelFeng1.Text = s[7];

                    labelDay2.Text = s[13].Trim();
                    labelTemp2.Text = s[12].Trim();
                    picDay21.Image = Image.FromFile(@"e:\weatherPic\" + s[15] + "");
                    picDay22.Image = Image.FromFile(@"e:\weatherPic\" + s[16] + "");
                    labelFeng2.Text = s[14].Trim();

                    labelDay3.Text = s[18].Trim();
                    labelTemp3.Text = s[17].Trim();
                    picDay31.Image = Image.FromFile(@"e:\weatherPic\" + s[20] + "");
                    picDay32.Image = Image.FromFile(@"e:\weatherPic\" + s[21] + "");
                    labelFeng3.Text = s[19].Trim();
                }

            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.Message.ToString());
            }
        }

        private void butDan_Click(object sender, EventArgs e)
        {
            ArrayList weather = new ArrayList();
            string tomorrow = "";
            if (labelDay1.Text.Length > 10)
            {
                weather.Add(labelDay1.Text.Substring(7, 4));
            }
            else
            {
                weather.Add(labelDay1.Text.Substring(7, 2));
            }
            if (labelDay2.Text.Length > 10)
            {
                weather.Add(labelDay2.Text.Substring(7, 4));
                tomorrow = labelDay2.Text.Substring(7, 4);
            }
            else
            {
                weather.Add(labelDay2.Text.Substring(7, 2));
                tomorrow = labelDay2.Text.Substring(7, 2);
            }
            if (labelDay3.Text.Length > 10)
            {
                weather.Add(labelDay3.Text.Substring(7, 4));
            }
            else
            {
                weather.Add(labelDay3.Text.Substring(7, 2));
            }

            //判断明天天气是否有雨
            if (tomorrow.Contains("雨"))
            {
                MessageBox.Show("明天有雨哦~亲！\r请根据策略确定明天是否灌溉！");
            }
            else
            {
                MessageBox.Show("明天没雨哦~亲！\r作物需要喷水灌溉！");
            }

        }
    }
}
